package com.taptech.doufu.ui.view.userdetail

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.google.gson.Gson
import com.taptech.doufu.R
import com.taptech.doufu.constant.Constant
import com.taptech.doufu.model.user.ListItem
import com.taptech.doufu.model.user.SumInfo
import com.taptech.doufu.services.personalcenter.AccountService
import com.taptech.doufu.ui.activity.PersonalAttentionsActivity
import com.taptech.doufu.ui.activity.PersonalFansActivity
import com.taptech.doufu.util.GsonUtil
import kotlinx.android.synthetic.main.view_user_detail_sum_info.view.*

class UserDetailSumInfoView(context: Context):LinearLayout(context) {


    init {
        initView()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.view_user_detail_sum_info,null)
        addView(view)
    }

    fun setData(uid:Int,data: ListItem) {
        try {
            if (AccountService.getInstance().isLogin && uid == AccountService.getInstance().userUid.toInt()) {
                tvFansDesc.text = "    关注我的"
                tvAttentionDesc.text = "    我的关注"
            }else{
                tvFansDesc.text = "    关注TA的"
                tvAttentionDesc.text = "    TA的关注"
            }
            val info:SumInfo = GsonUtil.parseJsonWithGson(Gson().toJson(data.data), SumInfo::class.java)
            tvLength.text = info.length.toString()
            tvCollectCount.text = info.fans_counts.toString()
            tvAttentionCount.text = info.attentions_counts.toString()
        } catch (e: Exception) {
            e.printStackTrace()
        }
        layAttention.setOnClickListener {
            val intent = Intent(context, PersonalAttentionsActivity::class.java)
            intent.putExtra(Constant.UID, "$uid")
            context.startActivity(intent)
        }
        layFans.setOnClickListener {
            // 腐小二的粉丝数不能点击
            if (uid != 50100){
                val intent = Intent(context, PersonalFansActivity::class.java)
                intent.putExtra(Constant.UID, "$uid")
                context.startActivity(intent)
            }
        }
    }
}
